<!DOCTYPE html>
<html lang="zh-cmn-Hans">
{% load staticfiles %}
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>钉钉用户信息</title>
    <link rel="stylesheet" type="text/css" href="{% static 'bootstrap/css/bootstrap.css' %}">
    <style type="text/css">
        .info-row {
            margin-top: 0;
            padding-bottom: 7px;
            margin-bottom: 21px;
            position: relative;
        }
    </style>

    <script src="{% static 'js/jquery.min.js' %}" type="text/javascript"></script>
    <script src="{% static 'bootstrap/js/bootstrap.js' %}" type="text/javascript"></script>
    <script src="https://g.alicdn.com/dingding/open-develop/1.6.9/dingtalk.js" type="text/javascript"></script>

    <script type="application/javascript">

        dd.ready(function () {
            dd.runtime.permission.requestAuthCode({
                corpId: "ding67cd4f2a4ac08ac035c2f4657eb6378f",
                onSuccess: function (info) {
                    //alert('authcode:' + info.code)
                    /*{
                        code: 'hYLK98jkf0m' //string authCode
                    }*/
                    $.ajax({
                        //url: 'userinfo?code=' + info.code + '&corpid=ding67cd4f2a4ac08ac035c2f4657eb6378f',
                        url: "/dingding/user_info?auth_code=" + info.code,
                        type: 'GET',
                        success: function (data, status, xhr) {
                            if (data['flag'] == '1') {
                                info = data['data']
                                document.getElementById("spanUserName").innerHTML = info.name;
                                document.getElementById("spanUserId").innerHTML = info.userid;
                                document.getElementById("spanTel").innerHTML = info.tel;
                                document.getElementById("spanMobile").innerHTML = info.mobile;
                                document.getElementById("spanEmail").innerHTML = info.email;
                                document.getElementById("spanPosition").innerHTML = info.position;

                                // 图片
                                if (info.avatar.length != 0) {
                                    var img = document.getElementById("userImg");
                                    img.src = info.avatar;
                                    img.height = '100';
                                    img.width = '100';
                                }
                            } else {
                                alert(data.msg)
                            }

                        },
                        error: function (xhr, errorType, error) {
                            logger.e("yinyien:" + _config.corpId);
                            alert(errorType + ', ' + error);
                        }
                    });
                },
                onFail: function (err) {
                    alert('error:' + err)
                }

            });


        });
    </script>
</head>
<body>
<div class="container">
    <div class="row info-row">
        <div class="col-md-2 col-xs-6 text-center">姓名：</div>
        <div class="col-md-4 col-xs-6 text-center"><span id="spanUserName"></span></div>
    </div>
    <div class="row info-row">
        <div class="col-md-2 col-xs-6 text-center">头像：</div>
        <div class="col-md-4 col-xs-6 text-center">
            <img id="userImg" alt="用户头像" class="img-circle"/><br>
        </div>

    </div>
    <div class="row info-row">
        <div class="col-md-2 col-xs-6 text-center">女神：</div>
        <div class="col-md-4 col-xs-6 text-center">
            <img src="{{ MEDIA_URL }}{{ zhao }}" height="100" width="100" alt="用户头像" class="img-circle"/>
        </div>

    </div>
    <div class="row info-row">
        <div class="col-md-2 col-xs-6 text-center">用户标识：</div>
        <div class="col-md-4 col-xs-6 text-center"><span id="spanUserId"></span></div>
    </div>
    <div class="row info-row">
        <div class="col-md-2 col-xs-6 text-center">联系电话：</div>
        <div class="col-md-4 col-xs-6 text-center"><span id="spanTel"></span></div>
    </div>
    <div class="row info-row">
        <div class="col-md-2 col-xs-6 text-center">手机号：</div>
        <div class="col-md-4 col-xs-6 text-center"><span id="spanMobile"></span></div>
    </div>
    <div class="row info-row">
        <div class="col-md-2 col-xs-6 text-center">邮箱：</div>
        <div class="col-md-4 col-xs-6 text-center"><span id="spanEmail"></span></div>
    </div>
    <div class="row info-row">
        <div class="col-md-2 col-xs-6 text-center">岗位：</div>
        <div class="col-md-4 col-xs-6 text-center"><span id="spanPosition"></span></div>
    </div>
</div>
</body>
</html>